package com.zw.yzk.kabu.mapper;

import com.zw.yzk.kabu.data.network.entity.ClassifyShopEntity;
import com.zw.yzk.kabu.data.network.entity.GoodsClassifyEntity;
import com.zw.yzk.kabu.model.ClassifyDetailsModel;
import com.zw.yzk.kabu.model.ClassifyShopModel;
import com.zw.yzk.kabu.model.GoodsClassifyModel;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by zhanwei on 2017/3/12.
 */

public class GoodsClassifyMapper {

    @Inject
    public GoodsClassifyMapper() {
    }

    public GoodsClassifyModel transfer(GoodsClassifyEntity.Classify classify) {
        GoodsClassifyModel model = new GoodsClassifyModel();
        model.setId(classify.id);
        model.setClassify(classify.content);

        return model;
    }

    public List<GoodsClassifyModel> transfer(GoodsClassifyEntity entity) {
        List<GoodsClassifyModel> modelList = new ArrayList<>();
        if (entity.result.classifyList == null || entity.result.classifyList.isEmpty()) {
            return modelList;
        }
        for (GoodsClassifyEntity.Classify classify : entity.result.classifyList) {
            modelList.add(transfer(classify));
        }
        if (!modelList.isEmpty()) {
            modelList.get(0).setSelected(true);
        }
        return modelList;
    }


    public List<ClassifyDetailsModel> transferClassify(ClassifyShopEntity entity) {
        List<ClassifyDetailsModel> result = new ArrayList<>();
        if (entity.result == null || entity.result.shopList.isEmpty()) {
            return result;
        }
        for (ClassifyShopEntity.SubClassify classify : entity.result.classifyList) {
            ClassifyDetailsModel model = new ClassifyDetailsModel();
            model.setImage(classify.image);
            model.setId(classify.id);
            model.setName(classify.content);

            result.add(model);
        }
        return result;
    }

    public List<ClassifyShopModel> transferShop(ClassifyShopEntity entity) {
        List<ClassifyShopModel> result = new ArrayList<>();
        if (entity.result == null || entity.result.shopList.isEmpty()) {
            return result;
        }
        for (ClassifyShopEntity.Shop shop : entity.result.shopList) {
            ClassifyShopModel model = new ClassifyShopModel();
            model.setImage(shop.image);
            model.setOwnerId(shop.ownerId);
            model.setShopId(shop.shopId);
            model.setShopName(shop.shopName);

            result.add(model);
        }
        return result;
    }
}
